package com.yjyw.tiexie.common;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.yjyw.tiexie.activity.login.LoginActivity;
import com.yjyw.tiexie.bean.SuccessBaseBean;
import com.yjyw.tiexie.common.net.NetCallBack;
import com.yjyw.tiexie.common.net.NetRequest;
import com.yjyw.tiexie.common.net.OkHttpUtil;
import com.yjyw.tiexie.util.ActivityManager;
import com.yjyw.tiexie.util.AndroidWorkaround;
import com.yjyw.tiexie.util.GsonUtil;
import com.yjyw.tiexie.util.LogUtil;
import com.yjyw.tiexie.util.Md5Util;
import com.yjyw.tiexie.util.QMUIStatusBarHelper;
import com.yjyw.tiexie.util.SharedPreferencesUtils;
import com.yjyw.tiexie.util.ToastUtil;
import com.yjyw.tiexie.view.FixedSpeedScroller;
import com.yjyw.tiexie.view.MyProgressDialog;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import butterknife.ButterKnife;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public abstract class BaseActivity extends AppCompatActivity implements BaseView {
    private static final int ERROR = 1;
    private static final int SUCCESS = 2;
    private String tag = this.getClass().getSimpleName();
    private Subscription mSubscription;
    private MyProgressDialog mProgressDialogNoMiss;
    private boolean lightMode = true;
    private boolean single = true;
    private Context mContext;
    //进度条的dialog
    protected ProgressDialog progress = null;

    private int lightType;

    protected static final String TAG = "BaseActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        DisplayUtil.setCustomDensity(this, getApplication());
        LogUtil.e(TAG, "当前启动的Activity名称为: "+getClass().getSimpleName());
        mContext = this;
        int layoutId = getContentView();
        if (layoutId != 0) {
            setContentView(layoutId);
        }
        //适配虚拟按键
        if (AndroidWorkaround.checkDeviceHasNavigationBar(this)) {
            AndroidWorkaround.assistActivity(findViewById(android.R.id.content));
        }
        ButterKnife.bind(this);
        setModeType(lightType);


        //网络请求成功 不自动消失
        mProgressDialogNoMiss = new MyProgressDialog(this);
        mProgressDialogNoMiss.setMessage("");
        init();
        ActivityManager.getInstance().addActivity(this);

        //禁止息屏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    public void setModeType(int lightType) {
        switch (lightType) {
            case 1:
                QMUIStatusBarHelper.immersive(this);
                QMUIStatusBarHelper.setStatusBarDarkMode(this);
                break;
            case 2:
                break;
            case 3:
                //不走沉浸式
                break;
            case 0:
                QMUIStatusBarHelper.immersive(this);
                QMUIStatusBarHelper.setStatusBarLightMode(this);
            default:
                QMUIStatusBarHelper.immersive(this);
                QMUIStatusBarHelper.setStatusBarLightMode(this);
                break;
        }
    }

    /**
     * 修改手机字体，不影响APP
     *
     * @return
     */
    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
        return res;
    }

    @Override
    public void showMessage(String msg) {
        ToastUtil.show(msg);
    }


    public void toast(String msg) {
        ToastUtil.show(msg);
    }

    public void showProgress(String message) {
        if (!TextUtils.isEmpty(message)) {
            mProgressDialogNoMiss.setMessage(message);
        } else {
            mProgressDialogNoMiss.setMessage("");
        }
        mProgressDialogNoMiss.setCancelable(true);
        mProgressDialogNoMiss.setCanceledOnTouchOutside(true);
        if (!mProgressDialogNoMiss.isShowing()) {
            mProgressDialogNoMiss.show();
        }
    }

    public void showProgressNoMiss(String message) {
        if (!TextUtils.isEmpty(message)) {
            mProgressDialogNoMiss.setMessage(message);
        } else {
            mProgressDialogNoMiss.setMessage("");
        }
        mProgressDialogNoMiss.setCancelable(false);
        mProgressDialogNoMiss.setCanceledOnTouchOutside(false);
        if (!mProgressDialogNoMiss.isShowing()) {
            mProgressDialogNoMiss.show();
        }
    }

    public void hideProgressNoMiss() {
        if (mProgressDialogNoMiss != null) {
            mProgressDialogNoMiss.dismiss();
        }
    }

    public void hideProgress() {
        if (mProgressDialogNoMiss != null) {
            mProgressDialogNoMiss.dismiss();
        }
    }


    protected abstract int getContentView();

    /**
     * 初始化
     */
    protected abstract void init();

    private boolean isFirst = true;


    @SuppressWarnings("Unchecked")
    protected <T extends View> T getViewById(int id) {
        return (T) findViewById(id);
    }

    public void post(HashMap map, String url, int requestCode, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
        HashMap hashMap;
        hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
            hideProgress();
            hideProgressNoMiss();
        } else {
            try {
                mSubscription = OkHttpUtil.getResult(request, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                hideProgress();
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }

                            }
                        });
            } catch (JSONException e) {
                LogUtil.e("JSONException", e.toString());
                hideProgress();
            } catch (Exception e) {
                e.printStackTrace();
                hideProgress();
            }
        }
    }


    public void postJson(HashMap map, String url, int requestCode, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
        HashMap hashMap;
        hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
            hideProgress();
            hideProgressNoMiss();
        } else {
            try {
                mSubscription = OkHttpUtil.getResultBean(request, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                hideProgress();
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        LogUtil.e("LoginActivity", "LoginActivity-------------BaseActivity255");
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }

                            }
                        });
            } catch (JSONException e) {
                LogUtil.e("JSONException", e.toString());
                hideProgress();
            } catch (Exception e) {
                e.printStackTrace();
                hideProgress();
            }
        }
    }

    public void putJson(HashMap map, String url, int requestCode, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
        HashMap hashMap;
        hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
            hideProgress();
            hideProgressNoMiss();
        } else {
            try {
                mSubscription = OkHttpUtil.getPutResultBean(request, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                hideProgress();
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        LogUtil.e("LoginActivity", "LoginActivity-------------BaseActivity255");
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }

                            }
                        });
            } catch (JSONException e) {
                LogUtil.e("JSONException", e.toString());
                hideProgress();
            } catch (Exception e) {
                e.printStackTrace();
                hideProgress();
            }
        }
    }

    private HashMap getTrueMap(HashMap map) {
        //排序
        Map<String, Object> sort_map = sortMapByKey(map);
        //map转json
        JSONObject json = new JSONObject(sort_map);
        String sign = Md5Util.md5(json.toString() + "|tel9009");
        map.put("sign", sign);
        LogUtil.e("json", json.toString() + "|tel9009");
        return map;
    }

    private HashMap getTrueMapJson(HashMap map) {
        //排序
        Map<String, Object> sort_map = sortMapByKey(map);
        //map转json
        JSONObject json = new JSONObject(sort_map);

        return map;
    }

    ;

    /**
     * 让 Map按key进行排序
     */
    public static Map<String, Object> sortMapByKey(Map<String, Object> map) {
        TreeMap<String, Object> sort_map = new TreeMap<>();

        for (Map.Entry<String, Object> me : map.entrySet()) {
            String key = me.getKey();
//            if ("sign".equals(key) || "json".equals(key)) {
//                continue;
//            }
            sort_map.put(key, me.getValue());
        }
        return sort_map;
    }


    public void get(HashMap map, String url, int requestCode, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
//        HashMap hashMap = getTrueMap(map);
        HashMap hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
            hideProgress();
            hideProgressNoMiss();
        } else {
            try {
                mSubscription = OkHttpUtil.getResultGet(request, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                hideProgress();
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        LogUtil.e("LoginActivity", "LoginActivity-------------BaseActivity255");
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            hideProgress();
                                        }

                                    }
                                }

                            }
                        });
            } catch (Exception e) {
                e.printStackTrace();
                hideProgress();
            }
        }
    }


    public void postFile(HashMap map, String url, int requestCode, File file, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
//        HashMap hashMap = getTrueMap(map);
        HashMap hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
        } else {
            try {
                mSubscription = OkHttpUtil.getResultFile(request, file, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        LogUtil.e("LoginActivity", "LoginActivity-------------BaseActivity255");
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }

                            }
                        });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public void postFileList(HashMap map, String pic_key, String url, int requestCode, List<File> files, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
//        HashMap hashMap = getTrueMap(map);
        HashMap hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
        } else {
            try {
                mSubscription = OkHttpUtil.getResultFileList(request, pic_key, files, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        LogUtil.e("LoginActivity", "LoginActivity-------------BaseActivity255");
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }

                            }
                        });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public void delete(HashMap map, String url, int requestCode, final NetCallBack callBack) {
        final NetRequest request = new NetRequest();
//        HashMap hashMap = getTrueMap(map);
        HashMap hashMap = map;
        request.url = url;
        request.params = hashMap;
        request.requestCode = requestCode;
        if (!OkHttpUtil.isNetworkAvailable(getApplicationContext())) {
            showMessage("请打开网络连接！！！");
        } else {
            try {
                mSubscription = OkHttpUtil.getDeleteResult(request, this).observeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                            }

                            @Override
                            public void onError(Throwable e) {
                                LogUtil.e("IOException e", e.toString());
                                showMessage("网络超时！稍后再试！");
                                try {
                                    callBack.onResponse(false, request.requestCode, "");
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                }

                            }

                            @Override
                            public void onNext(String s) {
                                int state = 1;
                                try {
                                    if (s == null || "".equals(s)) {
                                        state = ERROR;
                                    } else {
                                        state = SUCCESS;
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    s = e.toString();
                                    state = ERROR;
                                } finally {
                                    LogUtil.e(tag, s);
                                    if (request.requestCode != null) {
                                        try {
                                            if (state == ERROR) {
                                                callBack.onResponse(false, request.requestCode, s);

                                            } else {//处理token失效
                                                SuccessBaseBean bean = (SuccessBaseBean) GsonUtil.getObject(s, SuccessBaseBean.class);
                                                if (10902 == bean.getRetcode() || 10903 == bean.getRetcode()) {
                                                    if (isFirst) {
                                                        //token过期只走一次跳转登录界面
                                                        callBack.tokenTimeOut(request.requestCode);
                                                        isFirst = false;
                                                        SharedPreferencesUtils.clear(BaseActivity.this);

                                                        ActivityManager.getInstance().exit();
                                                        LogUtil.e("LoginActivity", "LoginActivity-------------BaseActivity255");
                                                        startActivity(new Intent(BaseActivity.this, LoginActivity.class));
                                                    }
                                                } else {
                                                    callBack.onResponse(true, request.requestCode, s);
                                                }
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }

                            }
                        });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mProgressDialogNoMiss != null) {
            mProgressDialogNoMiss.dismiss();
        }
        if (null != progress) {
            progress.dismiss();
        }
        //移除该activity
        ActivityManager.getInstance().deleteActivity(this);
    }


    /* 设置ViewPager的滑动速度
     *
     * */
    public void setViewPagerScrollSpeed(ViewPager viewPager) {
        try {
            Field mScroller = null;
            mScroller = ViewPager.class.getDeclaredField("mScroller");
            mScroller.setAccessible(true);
            FixedSpeedScroller scroller = new FixedSpeedScroller(viewPager.getContext());
            mScroller.set(viewPager, scroller);
        } catch (NoSuchFieldException e) {

        } catch (IllegalArgumentException e) {

        } catch (IllegalAccessException e) {

        }
    }

    /**
     * back
     *
     * @param view
     */
    public void back(View view) {
        finish();
    }


    protected void setInProgress(boolean busy, String title) {
        if (busy) {
            if (null == progress) {
                progress = new ProgressDialog(this);
                progress.setTitle(title);
                progress.setMessage("请稍等");
                progress.setCanceledOnTouchOutside(false);
            }
            progress.show();
        } else if (null != progress && progress.isShowing()) {
            progress.dismiss();
        }
    }

}
